<template>
  <el-tag class="tag-status"
          :effect="effect"
          v-if="label"
          :class="mapper"
          size="small"
          :type="currType"
          v-bind="$attrs"
  >
    <slot>
      {{label}}
    </slot>
  </el-tag>
</template>

<script>
import { mapState } from 'vuex'

const types = {
  jjcdMap: {
    1: 'primary',
    2: 'warning',
    3: 'danger'
  },
  meetingStatusMap: {
    0: 'primary',
    1: 'warning',
    2: 'success',
    3: 'danger'
  }
}

function getTypeByMapper(value, mapper) {
  if(types[mapper]) {
    return types[mapper][value] || ''
  }
  return 'primary'
}


export default {
  name: 'judge-status',
  cnName: '研判状态',
  props: {
    value: [String, Number],
    type: String,
    mapper: {
      type: String
    },
    effect: {
      type: String,
      default: 'light'
    }
  },
  data() {
    return {
      '01': {
        0: '否',
        1: '是'
      }
    }
  },
  methods: {},
  watch: {},
  computed: {
    label() {
      let rtn = this.value
      let map = {}
      map = this[this.mapper]
      if(!map) return this.value
      const value = map[this.value]
      rtn = value || rtn
      if(value && value.label) {
        return value.label
      }
      return rtn
    },
    currType() {
      if(this.type) {
        return this.type
      }
      let map = {}
      map = this[this.mapper]
      const value = map[this.value]
      if(value && value.type) {
        return value.type
      }

      return getTypeByMapper(this.value, this.mapper)
    },
    ...mapState('constant', [])
  },
  mounted() {

  }
}
</script>

<style lang="scss" scoped>
.tag-status {
  font-size: inherit;

}
</style>
